package duoxiancheng;

import com.sun.org.apache.bcel.internal.generic.NEW;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/23 :20:22
 * @Description
 */
public class MyRunnable implements Runnable{
    private int titck = 100;//因为Threa 构造函数的实参都是一个对象所以不用定义为static共用100
    Object obj  = new Object();
    @Override
    public void run() {
        while (true){
            synchronized(MyRunnable.class){
            if (titck>0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            System.out.println(Thread.currentThread().getName()+titck);
            titck--;
            }else {
                break;
            }
            }
        }
    }
}
class MyRunnableTest{
    public static void main(String[] args) {
        MyRunnable runnable = new MyRunnable();
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        Thread thread3 = new Thread(runnable);
        thread1.setName("线程1：");
        thread2.setName("线程2：");
        thread3.setName("线程3：");
        thread1.start();
        thread2.start();
        thread3.start();
        System.out.println("hhhhhhhhhh");
    }
}
